package me.luger.core.mvc.entity;

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by a on 2017/6/1.
 */
public class IntCodeResult {
    private int code;
    private String msg;
    private boolean success;
    private Map<String,Object> ext;


    private IntCodeResult(int code, boolean success,String msg,Object... args) {
        this.code = code;
        this.success = success;
        this.msg = MessageFormat.format(msg,args);
    }

    public static IntCodeResult success(String msg,Object... args){
        return new IntCodeResult(200,true,msg,args);
    }

    public static IntCodeResult error(String msg,Object... args){
        return new IntCodeResult(-1,false,msg,args);
    }

    public static IntCodeResult info(int code, String msg,Object... args){
        return new IntCodeResult(code,true,msg,args);
    }

    public static IntCodeResult info(int code){
        return new IntCodeResult(code,true,"");
    }

    public IntCodeResult addExt(String key,Object val){
        Map<String,Object> extObj = this.getExt();
        if(null == extObj){
            extObj = new HashMap<String, Object>();
        }
        extObj.put(key,val);
        this.setExt(extObj);
        return this;
    }
    public Object getExtVal(String key){
        return this.ext.get(key);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Map<String, Object> getExt() {
        return ext;
    }

    public void setExt(Map<String, Object> ext) {
        this.ext = ext;
    }
}
